package de.tum.in.eist.im.client;

import java.util.List;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

import de.tum.in.eist.im.shared.*;

/**
 * Interface for services that an EIST_IM server provides. The basic
 * functionality of the server requires only a subset of provided methods.
 * However for convenience and more flexibility in developing EIST_IM clients
 * different additional methods are provided. An implementation of ChatService
 * in provided in de.tum.in.eist.im.server.ChatServiceImpl class in
 * eist_im_server.jar.
 * 
 * @author zardosht
 * 
 */
@RemoteServiceRelativePath("chatService")
public interface ChatService extends RemoteService {

	/**
	 * Returns all events for this user. This method should be implemented in a
	 * blocking way. This method is used then for clients who use server push.
	 * See {@link http 
	 * http://code.google.com/p/google-web-toolkit-incubator/wiki/ServerPushFAQ}
	 * for more information.
	 * 
	 * @param user
	 * @return all new events that happened from the last client called this
	 *         method.
	 */
	List<AbstractEvent> getEventsBlocking(User user);

	/**
	 * Returns all messages that have been sent after the given timestamp.
	 * Clients that are implemented by successive polling should use this
	 * method. Every time that the client recive a NewMessageChunk it sets its
	 * last time stamp to the time stamp of NewMessageChunk. The next time that
	 * the client calls this method, it sends its last time stamp along.
	 * 
	 * @param lastTimestamp
	 * @return an instance of NewMessageChunk that contains all messages that
	 *         have arrived in the time between clientLastTimestamp and the time
	 *         server receives the call. Note that the new messages are returned
	 *         in the same order that they have arrived to the server
	 */
	NewMessagesChunk getNewMessages(long clientLastTimestamp);

	/**
	 * Sends a message to the server.
	 * 
	 * @param message
	 */
	void sendMessage(Message message, String groupName);

	/**
	 * Logins a user. The user must be registered and can be authenticated by
	 * the server.
	 * 
	 * @param user
	 * @return true if user could be authenticated, otherwise false (user is not
	 *         registered, or could not be authenticated).
	 */
	User login(User user);

	/**
	 * logs a user out.
	 * 
	 * @param user
	 * @return true if user could be successfully logged out.
	 */
	boolean logout(User user);

	/**
	 * registeres a new user.
	 * 
	 * @param newUser
	 * @return true if user could be registered successfully, false otherwise
	 */
	boolean registerNewUser(User newUser);

	/**
	 * returns a list of users currently logged in to chat.
	 * 
	 * @return
	 */
	List<User> getLoggedInUsers();

	/**
	 * Returns all messages for the given group.
	 * 
	 * @param for group
	 * @return list of messages(all)
	 */
	List<Message> getHistory(Group g);
	
	
	/**
	 * creates a new group.
	 * @param newGroup
	 * @return
	 */
	boolean createNewGroup(Group newGroup);
	
	void invitePersonToGroup(String groupName, User askingUser,
			String invitedUser);
	
	void acceptGroupInvite(String groupName, User acceptingUser);
	
	List<User> getGroupMembers(String groupName);

	List<String> getGroups(User user);
}

